
angular.module('vehicleCheckApp')

.controller('LoginCtrl', function($scope,$state, $http, $ionicLoading,_$toast, _vehicleData) {
    var user = {};
    user.username = "";
    if(localStorage.actno)	user.username = localStorage.actno
    $scope.user= user;
 
    $scope.loginSubmit = function(user) {
    	debugger;
		$ionicLoading.show({
          template: '正在更新数据，请耐心等待~'
        });
		_vehicleData.login(user).then(function(data){
			$ionicLoading.hide();
			if(data.success){
				//从服务器获取所有数据并存到webSql
				_vehicleData.getAllData().then(function(){
					localStorage.remember = "true";
					localStorage.actno = data.User.actno;
					localStorage.storecode = data.User.storecode;
					$state.go("vehicleCheck");
				});
			}else{
                _$toast.showShortCenter(data.msg);
			}
		},
		function(status){
			$ionicLoading.hide();
			console.log(status);
            _$toast.showShortCenter("错误状态："+status);
		});
    };
})